// pages/patientMessage/patientMessage.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    patientTel: '',
    patientName: '',
    patientOrderDate: '',
    logoLink: '',
    sickSketch: '',
    sickInfo: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.setData({    
      patientTel: JSON.parse(options.patientTel),
      patientName: JSON.parse(options.name),
      patientOrderDate: JSON.parse(options.patientOrderDate) 
    })
    console.log(this.data.patientName)
    console.log(this.data.patientTel)
    console.log(this.data.patientOrderDate)
    this.getPatientMessage()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getPatientMessage()
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getPatientMessage()
  },

  /**
   * 获取患者详情
   */
  getPatientMessage: function() {
    var that = this
    console.log(this.data.patientTel)
    console.log(this.data.patientOrderDate)
    wx.request({
      url: getApp().globalData.url + 'getPatientMessage',
      method: 'GET',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data: {
        doctorTel: getApp().globalData.username,
        patientTel: that.data.patientTel,
        bookDate: that.data.patientOrderDate,
      },
      success(res) {
        console.log(res.data)
        that.setData({
          logoLink: res.data.logoLink,
          sickSketch: res.data.sickSketch,
          sickInfo: res.data.sickInfo
        })
      },
      fail(res) {
        wx.showToast({
          title: '患者详情获取失败，请下拉刷新',
          icon: 'none',
          duration: 2000
        })
      }
    })
  }
})